package cn.com.nxt.txb;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.google.gson.Gson;

import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.HashMap;
import java.util.Map;

import cn.com.nxt.txb.httpdelegate.MeetingDelegate;
import cn.com.nxt.txb.util.AppUtil;

@ContentView(R.layout.activity_silent_mode)
public class SilentModeActivity extends BaseActivity {
    @ViewInject(R.id.tv_noopsyche)
    private TextView mNoopsycheTv;
    @ViewInject(R.id.tv_all)
    private TextView mAllTv;
    private MeetingDelegate delegate;
    private int model=-1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);//注解绑定
        delegate=new MeetingDelegate(this);
        if(MeetingSetActivity.model==1)
            mNoopsycheTv.setTextColor(getResources().getColor(R.color.main_color));
        else if(MeetingSetActivity.model==2)
            mAllTv.setTextColor(getResources().getColor(R.color.main_color));

    }

    @Event({R.id.ll_noopsyche,R.id.ll_all})
    private void onViewClick(View v) {
        switch (v.getId()) {
            case R.id.ll_noopsyche:
                model=1;
                setMeetingSettingInfo(model);
                break;
            case R.id.ll_all:
                model=2;
                setMeetingSettingInfo(model);
                break;
        }
    }

    private void setMeetingSettingInfo(int model){
        if(MeetingSetActivity.model==model){
            finish();
            return;
        }
        Map<String, String> map = new HashMap<>();
        map.put("mute_model", model+"");
        map.put("password", MeetingSetActivity.password);
        Gson gson = new Gson();
        showDialog("正在设置");
        Log.v("--setting--", gson.toJson(map));
        delegate.setMeetingSettingInfo(AppUtil.mUser.getToken(),gson.toJson(map),MeetingSetActivity.RESULT_SILENT_MODE);
    }

    @Override
    public void success(String result, byte flag) {
        super.success(result, flag);
        disDialog();
        MeetingSetActivity.model=model;
        Intent intent = new Intent();
        setResult(MeetingSetActivity.RESULT_SILENT_MODE, intent);
        finish();
    }
}
